﻿namespace DimensionsHelper.LanguageService.Syntax;

public class MetadataProperty : Declaration
{
    private Expression? _value;

    internal MetadataProperty(SyntaxNode? parent, Identifier name) :
        base(SyntaxKinds.MetadataProperty, SyntaxToken.Default, name, parent)
    {
    }

    /// <summary>
    ///     元数据属性值
    /// </summary>
    public Expression? Value => _value;


    public void Update(Expression value)
    {
        SetChildNullableField(ref _value, Expression.IsEmptyExpression, value);
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, NameIdentifier, Value);
    }
}


public static partial class NodeFactory
{
    public static MetadataProperty CreateMetadataProperty(SyntaxNode? parent, Identifier identifierName,
        Expression? value)
    {
        MetadataProperty property = new(parent, identifierName);
        if (value != null)
        {
            property.Update(value);
        }

        return property;
    }
}